/**
 * 
 */
package sg.edu.nus;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 * @author Christian
 *
 */
public class UnitTestDataGenerator implements TestDataGenerator {

	private Map<Integer, Integer[]> originalRoles;
	private List<Integer[]> usersWithPermissions;
	
	private Integer[][] roles = new Integer[][]{
		{1,2,4},
		{2,3,4},
		{2,3},
		{2,4},
		{2},
		{4},
	};
	
	private Integer[][] userPermissions = {
		{},
		{1,2,4},
		{2,3},
		{1,2,4},
		{1,2,4},
		{2,3,4},
		{2,3,4},
		{2,3},
		{2,3},
		{4},
		{4},
		{},
		{1,2,4},
		{1,2,4},
		{2,3,4},
		
	};
	
	public UnitTestDataGenerator() {
		super();
		// create roles
		originalRoles = createRolesWithPermissions();
		// create users
		usersWithPermissions = createUsersWithPermissions();
	}
	
	private Map<Integer, Integer[]> createRolesWithPermissions() {
		// create roles
		Map<Integer, Integer[]> res = new LinkedHashMap<Integer, Integer[]>();
		for(Integer[] role : roles) {
			res.put(Arrays.hashCode(role), role);
		}
		
		return res;
	}
	
	private List<Integer[]> createUsersWithPermissions() {
		// create users
		List<Integer[]> res = new ArrayList<Integer[]>();
		for(Integer[] arr : userPermissions) {
			res.add(arr);
		}
		
		return res;
	}
	
	public Map<Integer, Integer[]> getOriginalRoles() {
		return originalRoles;
	}

	public List<Integer[]> getUsersWithPermissions() {
		return usersWithPermissions;
	}
	
	public void dumpData() {
		int roleId = 0;
		System.out.println("\nTest roles with permissions:");
		for(Integer[] rolePermissions : originalRoles.values()) {
			System.out.println("Role=" + roleId + ", permissions: " + Arrays.toString(rolePermissions));
			roleId++;
		}
		int user = 0;
		System.out.println("\nTest users with permissions:");
		for(Integer[] userPermissions : getUsersWithPermissions()) {
			System.out.println("User=" + user + ", permissions: " + Arrays.toString(userPermissions));
			user++;
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		UnitTestDataGenerator gen = new UnitTestDataGenerator();
		gen.dumpData();
	}

}
